package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Banner;
import cn.wolfcode.wolf2w.domain.Strategy;
import cn.wolfcode.wolf2w.domain.Travel;
import cn.wolfcode.wolf2w.query.BannerQuery;
import cn.wolfcode.wolf2w.service.IBannerService;
import cn.wolfcode.wolf2w.service.IStrategyService;
import cn.wolfcode.wolf2w.service.ITravelService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping ("/banner")
public class BannerController {
    @Autowired
    private IBannerService bannerService;
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private ITravelService travelService;
    @RequestMapping ("/list")
    public String list(Model model, @ModelAttribute("qo") BannerQuery qo){
        Page<Banner> page = bannerService.query(qo);
        model.addAttribute("page",page);
        return  "banner/list";
    }

    @RequestMapping ("/delete")
    public Object delete(String id){
        bannerService.delete(id);
        //删除后提示用户,操作成功
        return  JsonResult.success();
    }
    @RequestMapping ("/saveOrUpdate")//saveOrUpdate
    @ResponseBody
    public Object saveOrUpdate(Banner banner){
        bannerService.saveOrUpdate(banner);
        return  JsonResult.success();
    }

    //新增/编辑 页面的下拉框二级联动
    @GetMapping("/getAllType")
    @ResponseBody
    public Object getAllType(){
        //所有的攻略集合
        List<Strategy> strategies = strategyService.listAll();
        //所有的游记集合
        List<Travel> travels = travelService.listAll();
       Map map= new HashMap<>();
        map.put("sts",strategies);
        map.put("ts",travels);
        //给前端获取出来
//        data.data获取   map.sts获取集合  map.sts获取集合
        return  JsonResult.success(map);
    }




}
